package Bank;

import java.util.Scanner;

public class CommandParser
{
	Scanner inputConsole = new Scanner(System.in);
	String line;
	Bank bank;
	
	public CommandParser(Bank bank)
	{
		this.bank = bank;
		bank.printHelp();
		System.out.println("input");
	}
	private String getConsoleLine()
	{
		return inputConsole.nextLine();
	}
	public void readConsole()
	{
		line = getConsoleLine();
		
		decideOption();
		
		while(inputConsole.hasNext())
		{
			line = getConsoleLine();
			decideOption();	
		}
		inputConsole.close();
	}
	private void decideOption()
	{
		if(line.equals("1"))
		{
			addMember();
		} 
		else if(line.equals("2"))
		{
			System.out.println("Print all bank accounts.");
			bank.printBankAccounts();			
		}
		else if(line.startsWith("3 "))
		{
			System.out.println("print bepaald account af, geef achternaam:");
			bank.printMember(line.substring(2));
		}
		else if(line.startsWith("9"))
		{
			System.out.println("Print members.");
			bank.printMembers();
		}
		else if(line.equals("h"))
		{
			bank.printHelp();
		}
		else
		{
			System.out.println("No function found for this key, try help [h]");
		} 
	}
	public Scanner getScanner()
	{
		return inputConsole;
	}
	public void addMember()
	{
		String firstName = null;
		String name = null;
		String place = null;
		int age = 0;
		Scanner in = new Scanner(System.in);
		System.out.print("first name?        :"); firstName = in.nextLine();
		System.out.print("last name?         :"); name = in.nextLine();
		System.out.print("where do you live? :"); place = in.nextLine();
		System.out.print("age?               :"); age = in.nextInt();
		
		System.out.println("First name  : " + firstName);
		System.out.println("Last name   : " + name);
		System.out.println("Place       : " + place);
		System.out.println("Age         : " + age);
		System.out.println("==========Added!==========");
		
		bank.addAccountOwner(name, firstName, place, age, 0, 0);
		readConsole();
		
		in.close();
	}
}
